package me.thinkjet.utils;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;

public class EmailSenderUtils {

	private static String uri = "http://localhost";

	public static void SendEmail(String key,String address) {
		EmailAttachment attachment = new EmailAttachment();
		try {
			attachment.setURL(new URL(uri + key));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		attachment.setDisposition(EmailAttachment.ATTACHMENT);
		attachment.setDescription("Apache logo");
		attachment.setName("Apache logo");

		// Create the email message
		MultiPartEmail email = new MultiPartEmail();
		email.setHostName("mail.myserver.com");
		try {
			email.addTo(address);
			email.setFrom("me@apache.org", "Me");
			email.setSubject("The logo");
			email.setMsg("Here is Apache's logo");
			// add the attachment
			email.attach(attachment);
			// send the email
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
}
